<?php
	class mdl_points extends modelFactory
	{
		function toSetting($aData)
		{
			foreach ($aData as $key => $var)
			{
				$this->system->setConf('points.'.$key,$var);
			}
		}

		function getSetting($aConf)
		{
			foreach ($aConf as $var)
			{
				$aData[$var] = $this->system->getConf('points.'.$var);
			}
			return $aData;
		}

		function regGetPoint($mem)
		{
			//数组字段意义依次为 '注册积分开关','开始时间','结束时间','积分'
			/*
			$aConf = array('onoff','startdate','enddate','point');
			foreach ($aConf as $var)
			{
				$aData[$var] = $this->system->getConf('points.'.$var);
			}
			*/
			$onoff = $this->system->getConf('points.onoff');
			$startdate = strtotime($this->system->getConf('points.startdate'));
			$enddate = strtotime($this->system->getConf('points.enddate'));
			$point = $this->system->getConf('points.point');
			if ($onoff)
			{
				if ($point == 0) return true;
				if ($mem['regtime']>$startdate && $mem['regtime']<$enddate)
				{
					$oMem = $this->system->loadModel('member/member');
					$aMem = $oMem->getMemIdByName($mem['uname']);
					$oMemPoint = $this->system->loadModel('trading/memberPoint');
					return $oMemPoint->chgPoint($aMem[0]['member_id'],$point,'reg_get_point');
					/*
					$sqlString = 'UPDATE '.DB_PREFIX.'members SET point='.$point.' WHERE uname=\''.$mem['uname'].'\'';
					if ($this->db->exec($sqlString)) return true;
					else return false;
					*/
				}
			}
			else return false;

		}
	}
?>